package com.arthas.arthasforsba.constant;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * 通用常量信息
 *
 * @author ruoyi
 */
@Component
public class Constants implements InitializingBean {
    /**
     * UTF-8 字符集
     */
    public static final String UTF8 = "UTF-8";

    public static final String SPLIT = "-";

    /**
     * GBK 字符集
     */
    public static final String GBK = "GBK";

    /**
     * http请求
     */
    public static final String HTTP = "http://";

    /**
     * https请求
     */
    public static final String HTTPS = "https://";

    /**
     * 通用成功标识
     */
    public static final String SUCCESS = "0";

    /**
     * 通用失败标识
     */
    public static final String FAIL = "1";

    /**
     * 登录成功
     */
    public static final String LOGIN_SUCCESS = "Success";

    /**
     * 注销
     */
    public static final String LOGOUT = "Logout";

    /**
     * 登录失败
     */
    public static final String LOGIN_FAIL = "Error";

    /**
     * 验证码 redis key
     */
    public static final String CAPTCHA_CODE_KEY = "captcha_codes:";

    /**
     * 登录用户 redis key
     */
    public static final String LOGIN_TOKEN_KEY = "login_tokens:";

    /**
     * 防重提交 redis key
     */
    public static final String REPEAT_SUBMIT_KEY = "repeat_submit:";

    /**
     * 验证码有效期（分钟）
     */
    public static final Integer CAPTCHA_EXPIRATION = 2;

    /**
     * 令牌
     */
    public static final String TOKEN = "token";

    /**
     * 令牌前缀
     */
    public static final String TOKEN_PREFIX = "Bearer ";

    /**
     * 令牌前缀
     */
    public static final String LOGIN_USER_KEY = "login_user_key";

    /**
     * 用户ID
     */
    public static final String JWT_USERID = "userid";

    /**
     * 用户名称
     */
    public static final String JWT_USERNAME = "sub";

    /**
     * 用户头像
     */
    public static final String JWT_AVATAR = "avatar";

    /**
     * 创建时间
     */
    public static final String JWT_CREATED = "created";

    /**
     * 用户权限
     */
    public static final String JWT_AUTHORITIES = "authorities";

    /**
     * 参数管理 cache key
     */
    public static final String SYS_CONFIG_KEY = "sys_config:";

    /**
     * 新闻管理 cache key
     */
    public static final String NEW_SITE_KEY = "new_site:";

    /**
     * 字典管理 cache key
     */
    public static final String SYS_DICT_KEY = "sys_dict:";

    /**
     * 资源映射路径 前缀
     */
    public static final String RESOURCE_PREFIX = "/profile";


    /**
     * 资源映射路径 前缀
     */
    public static final String RESOURCE_QZLM_PREFIX = "/arthas";


    /**
     * 资源映射路径 临时压缩包
     */
    public static final String RESOURCE_ZIP_PREFIX = "/zip";



    public static final String SCP_BAT_PATH = "classpath:bat/uploadFile.bat";


    @Value("${mock:false}")
    public Boolean mock;


    // 用户实现类
    public static String userService;
    // 部门实现类
    public static String orgService;
    // 菜单实现类
    public static String menuService;
    // 角色实现类
    public static String lmRoleService;
    // 用户角色关联 实现类
    public static String accountRoleService;

    // 本地User实现类
    public static final String UserInfoServiceImpl = "userInfoServiceImpl";
    // 远程获取支撑平台user实现类
    public static final String RestUserInfoServiceImpl = "restUserInfoServiceImpl";

    // 本地Org实现类
    public static final String OrgServiceImpl = "orgServiceImpl";
    // 远程获取支撑平台org 实现类
    public static final String RestOrgServiceImpl = "restOrgServiceImpl";

    // 本地menu实现类
    public static final String MenuServiceImpl = "menuServiceImpl";
    // 远程获取支撑平台menu 实现类
    public static final String RestMenuServiceImpl = "restMenuServiceImpl";

    // 本地lm role实现类
    public static final String LmRoleServiceImpl = "lmRoleServiceImpl";
    // 远程获取支撑平台 role实现类
    public static final String RestRoleServiceImpl = "restRoleServiceImpl";

    // 本地 用户角色关联 实现类
    public static final String AccountRoleServiceImpl = "accountRoleServiceImpl";
    // 远程 用户角色关联 实现类
    public static final String RestAccountRoleServiceImpl = "restAccountRoleServiceImpl";

    @Override
    public void afterPropertiesSet() throws Exception {
        if (mock) {
            userService = UserInfoServiceImpl;
            orgService = OrgServiceImpl;
            menuService = MenuServiceImpl;
            lmRoleService = LmRoleServiceImpl;
            accountRoleService = AccountRoleServiceImpl;
        } else {
            userService = RestUserInfoServiceImpl;
            orgService = RestOrgServiceImpl;
            menuService = RestMenuServiceImpl;
            lmRoleService = RestRoleServiceImpl;
            accountRoleService = RestAccountRoleServiceImpl;
        }
    }
}
